<!Doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,minimum-scale=1,user-scalable=no,maximum-scale=1,initial-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="keywords" content="" />
    <meta id="m1" itemprop="name" content="i幸会2017-2018超级课表，重新定义营销"/>
    <meta id="m2"  itemprop="image" content="http://api.ixinghui.com:81/ixinghui-share/img/sher.png" />
    <meta id="m3"  name="description" itemprop="description" content="这是一个全民营销的时代，不断学习才能先人一步" />
    <link rel="icon" href="../img/da.ico">
    <link href="../css/member.css" rel="stylesheet" type="text/css" />
    <title>注册</title>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/qzact/common/share/share.js"></script>
</head>
<body>
<img class="logo" src="../img/h5/logo.png" alt=""/>
<div class="loginTrans">登录</div>
<form id="j_form3" method="post" autocomplete="off">
    <ul>
        <li>
            <i class="phone_icon"></i>
            <input type="text" name="reg_username" class="inputHeight" placeholder="请输入手机号码">
        </li>
        <li>
            <i class="password_icon1"></i>
            <input type="text" class="inputHeight inputWidth" name="reg_yzm"  placeholder="请输入验证码">
            <button class="but" id="j_form-yzm">获取验证码</button>
        </li>
        <li>
            <i class="password_icon1"></i>
            <input  type="password" name="reg_password" class="inputHeight pass" placeholder="请输入8到20位密码">
        </li>
    </ul>
    <div class="parbot1">
        <input type="button" class="login_register" id="register" value="注册"/>
    </div>
</form>
<script type="text/javascript" src="../js/jquery-1.12.2.min.js"></script>
<script type="text/javascript" src="../js/md5.js"></script>
<script type="text/javascript" src="../js/session.js"></script>
<script type="text/javascript" src="../js/cookie.js"></script>
<script type="text/javascript" src="../js/plugin.js"></script>
<script type="text/javascript" src="../js/index.js"></script>
<script>
    $('.loginTrans').click(function(){
        window.location.href='login.html';
    })
    if(browser.versions.android){
        $(document).ready(function () {
            $('body').height($('body')[0].clientHeight);
        });
    }
//    console.log(browser.versions)
    $(function(){
        var inp=$('.inputHeight');
        for(var i=0;i<inp.length;i++){
            +function(i){
                $(inp[i]).focus(function(){
                    if(i==1){
                        $(inp[i]).prev().addClass('password_icon').removeClass('password_icon1')
                        $(inp[i]).parent().prev().children('i').addClass('phone_icon1').removeClass('phone_icon')
                        $(inp[i]).parent().next().children('i').addClass('password_icon1').removeClass('password_icon');
                        $(inp[i]).parent().css('borderBottomColor','#0AC1C5').siblings().css('borderBottomColor','#F4F4F4');
                    }else if(i==0){
                        $(inp[i]).prev().addClass('phone_icon').removeClass('phone_icon1')
                        $(inp[i]).parent().nextAll().children('i').addClass('password_icon1').removeClass('password_icon');
                        $(inp[i]).parent().next().children('button').css({'background':'#17dce1','color':'#fff'})
                        $(inp[i]).parent().css('borderBottomColor','#0AC1C5').siblings().css('borderBottomColor','#F4F4F4');
                    }else{
                        $(inp[i]).prev().addClass('password_icon').removeClass('password_icon1')
                        $(inp[i]).parent().prev().prev().children('i').addClass('phone_icon1').removeClass('phone_icon')
                        $(inp[i]).parent().prev().children('i').addClass('password_icon1').removeClass('password_icon');
                        $(inp[i]).parent().css('borderBottomColor','#0AC1C5').siblings().css('borderBottomColor','#F4F4F4');
                    }
                })
            }(i)

        }
    })
    var href = $.session.get('href');
    var loginType='login';
    var codeId;//注册获得的codeId
    $(function(){
        tap("#register",function(){
            var username = $("[name='reg_username']").val(),
                    yzm = $("[name='reg_yzm']").val(),
                    password = $("[name='reg_password']").val();
                    var pwd=hex_md5(password)
//            console.log(username ,pwd,password,codeId)
            if( $.trim(username) == "" ){
                $.tip(errorMsg.phone,800);
                return false;
            }
            if( !regular.phone.test(username) ){
                $.tip(regularMsg.phone,2000);
                return false;
            }
            if( $.trim(yzm) == "" ){
                $.tip(errorMsg.code,800);
                return false;
            }
            if( $.trim(password) == "" ){
                $.tip(errorMsg.password,800);
                return false;
            }
            if( !regular.password.test(password) ){
                $.tip(regularMsg.password,2000);
                return false;
            }
            $.ajax({
                url : endpoint + "registForH5" + jsonpoint,
                type : "POST",
                data : {
                    "phoneNo":username ,
                    "password":pwd,
                    "code":yzm,
                    "codeId":codeId
                },
                beforeSend: function(){
                    $.tip("正在注册，请稍后...",500);
                }
            }).done(function(data){
//                console.log(data)

                $.removeLoading();
                if(loginType == "reg"){
                    $.session.set("id",data.user.userId);
                    function isWeiXin(){
                        var ua = window.navigator.userAgent.toLowerCase();
                        if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                            return true;
                        }else{
                            return false;
                        }
                    }
                    if(isWeiXin()){
                        window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx245428584189430f&redirect_uri=http://api.ixinghui.com/ixinghui-share/member/memberDescription.html&response_type=code&scope=snsapi_base#wechat_redirect';
                    }else{
                        window.location.href='memberDescription.html';
                    }
                }else{//登录
                    console.log('注册失败')
                }
            }).fail(function(){
                $.tip("系统异常，请稍后重试",1000);
                window.location.href='rigisterFail.html';
            });
        });
        /*验证码*/
        tap("#j_form-yzm",function(index,element){
            var user_val=$("input[name='reg_username']").val();
            if(user_val==""){
                $.tip("请输入手机号码",800);
                return false;
            }else if(!regular.phone.test(user_val)){
                $.tip(regularMsg.phone,2000);
                return false;
            }else{
                $.ajax({
                    async: false,
                    type:"post",
                    url:endpoint + "getPhoneNoIsRegistForH5" + jsonpoint,
                    data:{
                        'phoneNo':user_val
                    },
                    cache: false,
                    success:function(data){
//                        console.log(data);
                        if(data.isRegist ===true){
                            $.tip(errorMsg.code1,800);
                            loginType='login';
                            return false;
                            //已经注册

                        }else if(data.isRegist ===false){

                            loginType='reg';
                            settime(element)
                        }
                    },
                    dataType:"json"
                });
//                loginType == 'reg' ? settime(element,'reg') : settime(element,'login');
            }
        });
    })

</script>
</body>
</html>